<?php

require_once 'ActionFramework/start.php';
require_once 'views/all.cls.php';

/**
 * This action is typically requested by following the url emailed to the user.
 */
class ContinueSignupAction extends Action {
	
	const INPUT_SECRET = "secret";
	
	public function __construct() {
		parent::__construct();
		// TODO: Don't allow this
		$this->add_input(ContinueSignupAction::INPUT_SECRET);
	}
	
	public function trigger($request) {
		$secret = $request[ContinueSignupAction::INPUT_SECRET];
		
		global $DB;
		if ($DB->signup_secret_exists($secret)){
			$signup_data = $DB->get_signup_user_data($secret);
			$view = new ContinueSignupView(
							$secret, 
							$signup_data[SignupAction::INPUT_NAME]
			);
		}
		else {
			// Let the StartAction handle this
			$start_action = new StartAction();
			$view = $start_action->trigger($request);
			$view->add_message("The link seems to be invalid. Did you already
								<a href='index.php#register'>register</a>?");
		}
		return $view;
	}
}

?>